<?php

namespace Biz\service\FineGoodsBrokeNews;

use Biz\service\wiki\WikiBasic;
use Doraemon\tools\HhzEnv;

class DrawerService
{
    /** @var int 家居神器 */
    public const TYPE_1 = 1;

    /** @var int 萌萌萌萌 */
    public const TYPE_2 = 2;

    /** @var int 设计好物 */
    public const TYPE_3 = 3;

    /** @var int 精选推荐 */
    public const TYPE_4 = 4;

    public const TYPE_5 = 5;

    public const TYPE_MAP_TEST = [
        self::TYPE_1 => [6709,6705,6884,6883,6882,6896,6897,6905,6904,6903,6902,6901,6900,6899,6898],
        self::TYPE_2 => [6708,1850,1848,1846],
        self::TYPE_3 => [6531],
        self::TYPE_4 => [6706],
        self::TYPE_5 => [6703],

    ];

    public const TYPE_MAP_PRO = [
        self::TYPE_1 => [235398,235397,235395,235394,235393,235392,235391,235389,235388,235387,235386,235385,235384,235383,235382,235381,235380,235379,235378,235377,235376,235375,235373,235372,235371,235369,235367,235366,235365,235364,235363,234172,234140,234139,234138,234137,234136,234135,234134,234133,234132,234131,234130,234129,234128,234127,234126,234125,234124,234123,234122,234121,234120,234119,234118,234117,234115,234114,234112,234110,234107,148162,121455,115517,110340,68566,57100,44520,28920,26096,23352,13962,881,234027,237554,236276,79898,30980,74244,239619,239086,236251,239565,168173,238098,237409,238611],
        self::TYPE_2 => [235421,235420,235419,235418,235417,235416,235415,235414,235413,235412,235411,235409,235407,235406,235405,235404,235403,235402,235400,235399,234163,234162,234161,234160,234159,234158,234157,234156,234152,234150,234149,234148,234147,234146,234143,234142,199286,199168,198967,196011,150975,140187,120912,109923,98361,63339,55078,28140,20143,4603,237506,239422],
        self::TYPE_3 => [82045,234087,55712,234088,195486,234090,38089,234091,234092,43634,50338,234093,234094,234164,148500,234167,234095,58488,104889,121437,79852,159094,45891,16006,105046,151142,234168,79702,119641,59768,80460,234097,81557,234098,234101,128980,151401,235422,235424,235425,235426,235427,235428,59461,235431,235433,235434,235435,46651,235437,22365,235440,238433,238729,159634,80523,239448,29629,238077],
        self::TYPE_4 => [1766,3655,8071,8189,8806,12887,15736,20140,23457,28401,32376,33976,44041,46238,48328,50812,56740,57478,57901,59384,60957,61691,71158,75501,77572,85009,85593,86439,87430,88174,90876,91878,94086,94462,100856,107277,107280,108518,111768,117569,121558,133391,135353,136523,137228,137428,141923,147586,147750,148961,151629,159202,162346,163166,166476,169333,185900,186632,187208,193050,195796,213500,213743,213861,214154,214685,233544,233545,233546,233547,234082,234084,234086,234089,234096,234099,234100,234102,234103,234105,234106,234108,234109,234111,234113,234116,234141,234144,234145,234151,234153,234154,234155,234171,235374,235423,235429,236009,236013,236267,236550,236554,236735,236788,237025,237343,237420,237541,237579,237960,238014,238054,238059,238628,238837,238843,238857,239031],
        self::TYPE_5 => [6703],
    ];

    public const PAGE_LIMIT = 10;

    /**
     * 获取抽屉列表
     * @param int $type
     * @param int $page
     * @return array
     * @throws \Exception
     */
    public static function list(int $type, int $page = 1)
    {
        $wikiID = array_slice(self::getTypeList()[$type], ($page - 1) * self::PAGE_LIMIT, self::PAGE_LIMIT);
        $list = FineGoodsBrokeNewsService::getWikiLists($wikiID);
        $isOver = $page * self::PAGE_LIMIT >= count(self::getTypeList()[$type]);
        $rs = [];
        $listMap = array_column($list,null,'basic_id');
        foreach ($wikiID as $item) {
            if(isset($listMap[$item])){
                $rs[] = $listMap[$item];
            }
        }
        return [$rs, $isOver];
    }

    private static function getTypeList()
    {
        if (HhzEnv::isGray() || HhzEnv::isProduction()) {
            $recommendWikiIdList = self::TYPE_MAP_PRO;
        } else {
            $recommendWikiIdList = self::TYPE_MAP_TEST;
        }
        return $recommendWikiIdList;
    }

    public static function getWikiID()
    {
        return array_merge(...array_values(self::getTypeList()));
    }
}